﻿using Adams.Shared;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Adams.Tests.Shared
{
    
    
    /// <summary>
    ///This is a test class for DateHelperUnitTest and is intended
    ///to contain all DateHelperUnitTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DateHelperUnitTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DiffMins
        ///</summary>
        [TestMethod()]
        public void DiffMinsUnitTest()
        {
            DateTime d1 = DateTime.UtcNow;
            DateTime d2 = DateTime.UtcNow;
            double expected = 0;
            double actual;
            actual = DateHelper.DiffMins(d2, d1);
            Assert.AreEqual(expected, actual);

            d1 = DateTime.UtcNow;
            d2 = DateTime.UtcNow.AddMinutes(-10);
            expected = 10;
            actual = DateHelper.DiffMins(d2, d1);
            Assert.AreEqual(expected, actual);

            d1 = DateTime.UtcNow;
            d2 = DateTime.UtcNow.AddMinutes(10);
            expected = -10;
            actual = DateHelper.DiffMins(d2, d1);
            Assert.AreEqual(expected, actual);

            d1 = DateTime.UtcNow;
            d2 = DateTime.UtcNow.AddHours(5);
            expected = -60 * 5;
            actual = DateHelper.DiffMins(d2, d1);
            Assert.AreEqual(expected, actual);

            d1 = DateTime.UtcNow;
            d2 = DateTime.UtcNow.AddDays(1);
            expected = -60 * 24;
            actual = DateHelper.DiffMins(d2, d1);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void DiffDaysUnitTest()
        {
            DateTime d1 = DateTime.UtcNow;
            DateTime d2 = DateTime.UtcNow;
            double expected = 0;
            double actual;
            actual = DateHelper.DiffDays(d1, d2);
            Assert.AreEqual(expected, actual);

            d1 = new DateTime(2010, 1, 1);
            d2 = new DateTime(2010, 12, 31);
            expected = 364;
            actual = DateHelper.DiffDays(d1, d2);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void RoundUpToNextMinuteUnitTest()
        {
            DateTime d = DateTime.Parse("1/1/2010 5:44 PM");
            int increment = 5;
            DateTime expected = DateTime.Parse("1/1/2010 5:45 PM");
            DateTime actual;
            actual = DateHelper.RoundUpToNextMinute(d, increment);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/1/2010 5:44 PM");
            increment = 15;
            expected = DateTime.Parse("1/1/2010 5:45 PM");
            actual = DateHelper.RoundUpToNextMinute(d, increment);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void RoundUpToNextHourUnitTest()
        {
            DateTime d = DateTime.Parse("1/1/2010 5:44 PM");
            DateTime expected = DateTime.Parse("1/1/2010 6:00 PM");
            DateTime actual;
            actual = DateHelper.RoundUpToNextHour(d);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/1/2010 5:00 PM");
            expected = DateTime.Parse("1/1/2010 6:00 PM");
            actual = DateHelper.RoundUpToNextHour(d);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GetDayOccuranceUnitTest()
        {
            DateTime d = DateTime.Parse("1/1/2010 5:44 PM");
            int expected = 1;
            int actual = 0;
            actual = DateHelper.GetDayOccurance(d);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/10/2010 5:44 PM");
            expected = 2;
            actual = DateHelper.GetDayOccurance(d);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/17/2010 5:44 PM");
            expected = 3;
            actual = DateHelper.GetDayOccurance(d);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/24/2010");
            expected = 4;
            actual = DateHelper.GetDayOccurance(d);
            Assert.AreEqual(expected, actual);

            d = DateTime.Parse("1/31/2010");
            expected = 5;
            actual = DateHelper.GetDayOccurance(d);
            Assert.AreEqual(expected, actual);
        }
    }
}
